package tutorial.java.dragdrop;

import java.awt.BorderLayout;
import java.awt.EventQueue;

import javax.swing.JFrame;
import javax.swing.JPanel;
import javax.swing.border.EmptyBorder;
import javax.swing.JTextArea;
import javax.swing.JButton;
import java.awt.event.ActionListener;
import java.awt.event.ActionEvent;

public class TextAreaDemo extends JFrame {

	private JPanel contentPane;
	private JTextArea textAreaDescription;
	private String description;

	/**
	 * Launch the application.
	 */
	public static void main(String[] args) {
		EventQueue.invokeLater(new Runnable() {
			public void run() {
				try {
					TextAreaDemo frame = new TextAreaDemo();
					frame.setVisible(true);
				} catch (Exception e) {
					e.printStackTrace();
				}
			}
		});
	}

	/**
	 * Create the frame.
	 */
	public TextAreaDemo() {
		setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
		setBounds(100, 100, 450, 300);
		contentPane = new JPanel();
		contentPane.setBorder(new EmptyBorder(5, 5, 5, 5));
		setContentPane(contentPane);
		contentPane.setLayout(null);
		
		textAreaDescription = new JTextArea();
		textAreaDescription.setLineWrap(true);
		textAreaDescription.setWrapStyleWord(true);
		textAreaDescription.setBounds(0, 0, 434, 222);
		contentPane.add(textAreaDescription);
		
		JButton btn_Undo = new JButton("Undo");
		btn_Undo.addActionListener(new ActionListener() {
			public void actionPerformed(ActionEvent e) {
				textAreaDescription.setText(description);
			}
		});
		btn_Undo.setBounds(345, 233, 89, 23);
		contentPane.add(btn_Undo);
		
		JButton btn_Clear = new JButton("Clear");
		btn_Clear.addActionListener(new ActionListener() {
			public void actionPerformed(ActionEvent e) {
				if (!textAreaDescription.getText().equals("")) {
					description = textAreaDescription.getText();
				}
				textAreaDescription.setText("");
			}
		});
		btn_Clear.setBounds(246, 233, 89, 23);
		contentPane.add(btn_Clear);
	}
}
